package base.service.impl;


import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import base.dao.StudentDao;
import base.model.Student;
import base.service.StudentService;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;


/**
 * 
 * @author xiaozewen
 * @version  2016-11-25 19:53:54
 */
@Service
public class StudentServiceImpl  extends BaseServiceImpl<Student> implements StudentService {
	@Autowired
    private StudentDao studentDao;
	
	@Override
	public int delete(String ids) {
		Example example = new Example(Student.class);
		example.createCriteria().andIn("id", Arrays.asList(ids.split(",")));
		return studentDao.deleteByExample(example);
	}

	@Override
	public List<Student> list(Student student) {
		Example example=new Example(Student.class);
		Criteria criteria = example.createCriteria();
		List<Student> students = studentDao.selectByExample(example);
		return students;
	}

	@Override
	public PageInfo<Student> listPage(Student student,Integer pageNum,Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Example example=new Example(Student.class);
		Criteria criteria = example.createCriteria();
		if(StringUtils.isNotBlank(student.getName())){
			criteria.andLike("name", "%%"+student.getName()+"%%");
		}
		List<Student> students = studentDao.selectByExample(example);
		return new PageInfo<Student>(students);
	}

	@Override
	public List<Map<String, Object>> search(String name) {
		return studentDao.search(name);
	}

}
